﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace DesignPatternStudy.Creations.Singletons
{
    class CASSingleton
    {
        private static CASSingleton _instance;

        private CASSingleton()
        {
            Console.WriteLine("CASSingleton");
        }

        public static CASSingleton Singleton
        {
            get
            {
                if (_instance != null)
                {
                    return _instance;
                }

                Interlocked.CompareExchange(ref _instance, new CASSingleton(), null);

                return _instance;
            }
        }
    }
}
